﻿#region Librerias

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
using System.Xml;

#endregion


namespace ESF.General
{
	[Serializable]
	public class GenericValidationException : GenericException
	{
		#region Constructor

		protected GenericValidationException (SerializationInfo info, StreamingContext context) : base(info, context) { }


		public GenericValidationException(string pMessage, string pRelatedFileName, int? pLineNumber = null, int? pLinePosition = null, string pRelatedRegType = null, string pRelatedFieldName = null, string pRelatedValue = null) : 
			base (GenericException.INFO_INVALID_FORMAT, pMessage)
		{
			RelatedFilename = pRelatedFieldName;
			RelatedFieldname = pRelatedFieldName;
			RelatedValue = pRelatedValue;
			RelatedRegType = pRelatedRegType;

			LineNumber = pLineNumber;
			LinePosition = pLinePosition;			
		}

		#endregion


		#region Methods

		public override string ToString()
		{
			return GenericException.ToString (this);
		}


		public void ToXML (XmlWriter pWriter)
		{
			pWriter.WriteStartElement ("GenericValidationException");
						
			if (!string.IsNullOrEmpty (RelatedFilename))
			{
				pWriter.WriteAttributeString ("RelatedFilename", RelatedFilename);
			}

			if (!string.IsNullOrEmpty(RelatedFieldname))
			{
				pWriter.WriteAttributeString("RelatedFieldname", RelatedFieldname);
			}

			if (!string.IsNullOrEmpty(RelatedValue))
			{
				pWriter.WriteAttributeString("RelatedValue", RelatedValue);
			}

			if (!string.IsNullOrEmpty(RelatedRegType))
			{
				pWriter.WriteAttributeString("RelatedRegType", RelatedRegType);
			}

			if (LineNumber != null)
			{
				pWriter.WriteAttributeString("LineNumber", LineNumber.ToString ());
			}

			if (LinePosition != null)
			{
				pWriter.WriteAttributeString("LinePosition", LinePosition.ToString ());
			}

			pWriter.WriteEndElement ();
		}

		#endregion
	}
}
